<template>
  <div class="change-class body-bg">
    <div v-if="!initLoading">
      <!-- 课程信息 -->
      <div class="class-infor border-bottom">
        <img class="class-fengmian" :src="classInfor.fengmian" alt="封面">
        <ul class="infor-right">
          <li class="class-name overflow-one">{{classInfor.name}}</li>
          <li class="infor-text">{{classInfor.classIndex}}</li>
          <li class="infor-text">教练：{{classInfor.teacherName}}</li>
        </ul>
      </div>
      <!-- 评语 -->
      <div class="pingyu">
        <van-field
          :readonly="readonly"
          :value="message"
          type="textarea"
          placeholder="请对教师作出评价"
          autosize
          border="false"
          @change="changeMeg"
        />
      </div>
      <!-- 评星 -->
      <div class="pingxing">
        <p class="pingxing-title">课程评价</p>
        <div class="xing-items">学习效果 <van-rate :readonly="readonly" value="effect" color="#F39800" void-color="#F39800" @change="onChangeEffect" /></div>
        <div class="xing-items">课后服务 <van-rate :readonly="readonly" value="service" color="#F39800" void-color="#F39800" @change="onChangeService" /></div>
        <div class="xing-items">教学态度 <van-rate :readonly="readonly" value="attitude" color="#F39800" void-color="#F39800" @change="onChangeAttitude" /></div>
      </div>
      <div v-if="!readonly" class="submit-btn" @click="submit">提交评价</div>
    </div>
    <div v-else class="init-loading"><van-loading type="spinner" color="#1989fa" /></div>
  </div>
</template>

<script>
import store from '../../store/globalStore'
export default {
  data() {
    return {
      initLoading: true, // 初始加载
      readonly: false,
      effect: 0,
      service: 0,
      attitude: 0,
      message: "", // 评论
      classInfor: {
        fengmian: "https://img.yzcdn.cn/vant/cat.jpeg",
        name: "半年-60分钟课程一班",
        classIndex: "第二课次",
        teacherName: "陈念",
      }
    }
  },
  onLoad(e) {
    if(e.isEva == "1"){ // 已评价，回写即可
      this.readonly = true;
    } else { // 未评价，可以编辑
      this.readonly = false;
    }
  },
  onShow() {
    this.getShiftWorkList();
  },
  methods: {
    // 获取列表
    getShiftWorkList() {
      this.$fetch.shiftWork()
      .then(res=>{
        this.initLoading = false;
      }).catch(err=>{
        this.initLoading = false;
      })
    },
    // 评星
    onChangeEffect(e) {
      this.effect = e.mp.detail;
    },
    onChangeService(e) {
      this.service = e.mp.detail;
    },
    onChangeAttitude(e) {
      this.effect = e.mp.detail;
    },
    // 评论语
    changeMeg(e) {
      this.message = e.mp.detail.trim();
      console.log(this.message)
    },
    // 报名
    submit() {
      console.log(this.message)
      // wx.redirectTo({
      //   url: '/pages/evaluateList/main'
      // })
    }
  },
}
</script>

<style lang="less">
.pingyu{
  .van-cell{
    background: #F1F2F7 !important;
    padding: 10px 10px 5px 10px !important;
    line-height: 30px;
  }
}
</style>
<style lang="less" scope>
.change-class{
  width: 100%;
  min-height: 100vh;
  .class-infor{
    width: 100%;
    padding: 18px 14px;
    box-sizing: border-box;
    background: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .class-fengmian{
      width: 94px;
      min-width: 94px;
      height: 70px;
      display: block;
    }
    .infor-right{
      flex-grow: 1;
      margin-left: 14px;
      .class-name{
        width: 100%;
        font-size: 14px;
        color: #333;
      }
      .infor-text{
        width: 100%;
        font-size: 12px;
        color: #939393;
        margin-top: 12px;
      }
    }
  }
  .pingyu{
    width: 100%;
    padding: 18px 14px;
    box-sizing: border-box;
    background: #fff;
    ._van-field{
      background: #F1F2F7;
    }
  }
  .pingxing{
    width: 100%;
    padding: 18px 14px;
    box-sizing: border-box;
    background: #fff;
    margin-top: 10px;
    .pingxing-title{
      width: 100%;
      font-size: 18px;
      color: #333;
    }
    .xing-items{
      width: 100%;
      font-size: 14px;
      color: #333;
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-top: 20px;
    }
  }
  .submit-btn{
    display: flex;
    justify-content: center;
    align-items: center;
    width: 300px;
    height: 44px;
    background:rgba(0,184,238,1);
    border-radius: 22px;
    font-size: 16px;
    color: #fff;
    font-weight: bold;
    margin: 30px auto;
  }
}
</style>
